﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Small.PinBan.PB.View;
using SmallERP.MODEL.PBModel;
using Small.PinBan.PB.Presenter;
using SmallERP.PinBan.PB.Presenter;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid.Views.Grid;
using Small.PinBan.PB.Comm;
using SmallERP.PinBan.PB.Froms;
using SmallERP.MODEL.FoundationModel;
using Small.PinBan.PB.Froms;
using Smallerp.Contracts.DataContracts;
using Smallerp.Contracts;
using System.ServiceModel;
using SmallERP.COM;
using SmallERP.PinBan;
using System.IO;

namespace Small.PinBan
{
    public partial class FrmMain_PinBan : Form, IPBMainView
    {
        private PBMainPresenter _presenter;


        private int _curSelectOrderProductId = 0;//当前左边列表中当前被选中的产品ID，当更新时用于固定选择列表
        private int _curSelectSizeIndex = -1;
        private int _curSelectOrderRowid = -1;
        private int _curSelectPhotoRowId = -1;
        private bool _displayAuto = false;
        public FrmMain_PinBan()
        {
            InitializeComponent();
            _presenter = new PBMainPresenter(this);
        }
        public static FrmMain_PinBan _instance;
        public static FrmMain_PinBan GetInstince
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmMain_PinBan();
                }
                return _instance;

            }
        }

        private void gvOrderInfo_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            //点击某行后就需绑定照片列表
            if (e.RowHandle > -1)
            {
                //_presenter.SelectOrder();
                //_view.SetSelected();
                _curSelectOrderRowid = e.RowHandle;
            }
        }

        private void btnRush_Click(object sender, EventArgs e)
        {
            btnRush.Enabled = false;
            this.Cursor = Cursors.WaitCursor;
            OrderInfo_PBDCT curOrder = (OrderInfo_PBDCT)gvOrderInfo.GetRow(gvOrderInfo.FocusedRowHandle);
            if (curOrder != null)
            {
                _curSelectOrderProductId = curOrder.order_Base_Info.OrderProductId;
                _curSelectOrderRowid = gvOrderInfo.FocusedRowHandle;
                _curSelectSizeIndex = -1;
            }
            _presenter.RushBind(true);
            this.Cursor = Cursors.Default;
            btnRush.Enabled = true;
        }
        private void ShowImport()
        {

        }

        private void gvOrderInfo_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            ////点击某行后就需绑定照片列表
            //if (e.FocusedRowHandle > -1)
            //{
            //    OrderInfo_PBDCT curOrder = (OrderInfo_PBDCT)gvOrderInfo.GetRow(e.FocusedRowHandle);     
            //    GcPhotoInfo.DataSource = curOrder.PhotoList;
            //    gvPhotoInfo.RefreshData();
            //}
            //_presenter.SelectOrder();


            //if (gvOrderInfo.IsGroupRow(e.FocusedRowHandle))
            //{
            //    int rowHandles=gvOrderInfo.GetChildRowCount(e.FocusedRowHandle);
            //    int endIndex = gvOrderInfo.GetChildRowHandle(e.FocusedRowHandle, rowHandles - 1);
            //    int startIndex = gvOrderInfo.GetChildRowHandle(e.FocusedRowHandle, 0);
            //    gvOrderInfo.ExpandGroupRow(e.FocusedRowHandle, false);
            //    gvOrderInfo.ClearSelection();
            //    gvOrderInfo.SelectRows(startIndex, endIndex); 
            //}

        }

        #region help methods

        /// <summary>
        /// 画刻度线
        /// </summary>
        public void DrawScaleLine()
        {
            //int startX = axPanelPB.Left;
            //int startY = axPanelPB.Top;

            //int currentX = startX;
            //int currentY = startY;

            //int num = 0;

            //Graphics g = this.CreateGraphics();
            //g.Clear(this.BackColor);
            //Pen p = new Pen(Color.Black, 1);

            //while (num * DataTransfer.PERPIXEL < axPanelPB.Width)
            //{
            //    switch (num % 4)
            //    {
            //        case 0:
            //            g.DrawLine(p, currentX, currentY, currentX, currentY - 20);

            //            Rectangle rect = new Rectangle(currentX + 1, currentY - 20, 25, 15);
            //            Font aFont = new Font("Arial", 6, FontStyle.Regular);
            //            g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
            //            aFont.Dispose();

            //            break;
            //        case 1:
            //        case 3:
            //            g.DrawLine(p, currentX, currentY, currentX, currentY - 8);
            //            break;
            //        case 2:
            //            g.DrawLine(p, currentX, currentY, currentX, currentY - 12);
            //            break;
            //        default:
            //            break;
            //    }
            //    num++;
            //    currentX += Convert.ToInt32(DataTransfer.PERPIXEL);
            //}

            //currentX = startX;
            //currentY = startY;
            //num = 0;
            //while (num * DataTransfer.PERPIXEL <= axPanelPB.Height)
            //{
            //    if (num * DataTransfer.PERPIXEL == axPanelPB.Height)
            //    {
            //        g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

            //        Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
            //        Font aFont = new Font("Arial", 6, FontStyle.Regular);
            //        g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
            //        aFont.Dispose();
            //    }
            //    else
            //    {
            //        switch (num % 4)
            //        {
            //            case 0:
            //                g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

            //                Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
            //                Font aFont = new Font("Arial", 6, FontStyle.Regular);
            //                g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
            //                aFont.Dispose();

            //                break;
            //            case 1:
            //            case 3:
            //                g.DrawLine(p, currentX, currentY, currentX - 8, currentY);
            //                break;
            //            case 2:
            //                g.DrawLine(p, currentX, currentY, currentX - 12, currentY);
            //                break;
            //            default:
            //                break;
            //        }
            //    }
            //    num++;
            //    currentY += Convert.ToInt32(DataTransfer.PERPIXEL);
            //}

            //p.Dispose();


            try
            {
                int perPixel = DataTransfer.PERPIXEL;
                if (ComboBoxUnit.SelectedIndex == 0)
                {

                    int startX = axPanelPB.Left;
                    int startY = axPanelPB.Top;

                    int currentX = startX;
                    int currentY = startY;

                    int num = 0;

                    Graphics g = this.CreateGraphics();
                    g.Clear(this.BackColor);
                    Pen p = new Pen(Color.Black, 1);

                    while (num * perPixel < axPanelPB.Width)
                    {
                        switch (num % 4)
                        {
                            case 0:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 20);

                                Rectangle rect = new Rectangle(currentX + 1, currentY - 20, 25, 15);
                                Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                                aFont.Dispose();

                                break;
                            case 1:
                            case 3:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 8);
                                break;
                            case 2:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 12);
                                break;
                            default:
                                break;
                        }
                        num++;
                        currentX += Convert.ToInt32(perPixel);
                    }

                    currentX = startX;
                    currentY = startY;
                    num = 0;
                    while (num * perPixel <= axPanelPB.Height)
                    {
                        if (num * perPixel == axPanelPB.Height)
                        {
                            g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                            Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
                            Font aFont = new Font("Arial", 7, FontStyle.Regular);
                            g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                            aFont.Dispose();
                        }
                        else
                        {
                            switch (num % 4)
                            {
                                case 0:
                                    g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                                    Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
                                    Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                    g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                                    aFont.Dispose();

                                    break;
                                case 1:
                                case 3:
                                    g.DrawLine(p, currentX, currentY, currentX - 8, currentY);
                                    break;
                                case 2:
                                    g.DrawLine(p, currentX, currentY, currentX - 12, currentY);
                                    break;
                                default:
                                    break;
                            }
                        }
                        num++;
                        currentY += Convert.ToInt32(perPixel);
                    }

                    p.Dispose();
                }
                else
                {
                    int startX = axPanelPB.Left;
                    int startY = axPanelPB.Top;

                    int currentX = startX;
                    int currentY = startY;

                    int num = 0;

                    Graphics g = this.CreateGraphics();
                    g.Clear(this.BackColor);
                    Pen p = new Pen(Color.Black, 1);

                    while (num * perPixel < axPanelPB.Width)
                    {
                        switch (num % 4)
                        {
                            case 0:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 20);

                                Rectangle rect = new Rectangle(currentX + 1, currentY - 20, 30, 15);
                                Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                                aFont.Dispose();

                                break;
                            case 1:
                            case 3:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 8);
                                break;
                            case 2:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 12);
                                break;
                            default:
                                break;
                        }
                        num++;
                        currentX += Convert.ToInt32(perPixel);
                    }

                    currentX = startX;
                    currentY = startY;
                    num = 0;
                    while (num * perPixel <= axPanelPB.Height)
                    {
                        if (num * perPixel == axPanelPB.Height)
                        {
                            g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                            Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 30, 15);
                            Font aFont = new Font("Arial", 7, FontStyle.Regular);
                            g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                            aFont.Dispose();
                        }
                        else
                        {
                            switch (num % 4)
                            {
                                case 0:
                                    g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                                    Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 30, 15);
                                    Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                    g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                                    aFont.Dispose();

                                    break;
                                case 1:
                                case 3:
                                    g.DrawLine(p, currentX, currentY, currentX - 8, currentY);
                                    break;
                                case 2:
                                    g.DrawLine(p, currentX, currentY, currentX - 12, currentY);
                                    break;
                                default:
                                    break;
                            }
                        }
                        num++;
                        currentY += Convert.ToInt32(perPixel);
                    }

                    p.Dispose();
                }



            }
            catch
            {
                MessageBox.Show("画线出错");
            }
        }

        /// <summary>
        /// 画刻度线
        /// </summary>
        public void DrawScaleLine2()
        {


            try
            {
                int perPixel = DataTransfer.PERPIXEL;
                if (ComboBoxUnit.SelectedIndex == 0)
                {

                    int startX = axPanelPB.Left;
                    int startY = axPanelPB.Top;

                    int currentX = startX;
                    int currentY = startY;

                    int num = 0;

                    Graphics g = this.CreateGraphics();
                    g.Clear(this.BackColor);
                    Pen p = new Pen(Color.Black, 1);

                    while (num * perPixel < axPanelPB.Width)
                    {
                        switch (num % 4)
                        {
                            case 0:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 20);

                                Rectangle rect = new Rectangle(currentX + 1, currentY - 20, 25, 15);
                                Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                                aFont.Dispose();

                                break;
                            case 1:
                            case 3:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 8);
                                break;
                            case 2:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 12);
                                break;
                            default:
                                break;
                        }
                        num++;
                        currentX += Convert.ToInt32(perPixel);
                    }

                    currentX = startX;
                    currentY = startY;
                    num = 0;
                    while (num * perPixel <= axPanelPB.Height)
                    {
                        if (num * perPixel == axPanelPB.Height)
                        {
                            g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                            Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
                            Font aFont = new Font("Arial", 7, FontStyle.Regular);
                            g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                            aFont.Dispose();
                        }
                        else
                        {
                            switch (num % 4)
                            {
                                case 0:
                                    g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                                    Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 15, 15);
                                    Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                    g.DrawString(num.ToString(), aFont, Brushes.Black, rect);
                                    aFont.Dispose();

                                    break;
                                case 1:
                                case 3:
                                    g.DrawLine(p, currentX, currentY, currentX - 8, currentY);
                                    break;
                                case 2:
                                    g.DrawLine(p, currentX, currentY, currentX - 12, currentY);
                                    break;
                                default:
                                    break;
                            }
                        }
                        num++;
                        currentY += Convert.ToInt32(perPixel);
                    }

                    p.Dispose();
                }
                else
                {
                    int startX = axPanelPB.Left;
                    int startY = axPanelPB.Top;

                    int currentX = startX;
                    int currentY = startY;

                    int num = 0;

                    Graphics g = this.CreateGraphics();
                    g.Clear(this.BackColor);
                    Pen p = new Pen(Color.Black, 1);

                    while (num * perPixel < axPanelPB.Width)
                    {
                        switch (num % 4)
                        {
                            case 0:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 20);

                                Rectangle rect = new Rectangle(currentX + 1, currentY - 20, 30, 15);
                                Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                                aFont.Dispose();

                                break;
                            case 1:
                            case 3:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 8);
                                break;
                            case 2:
                                g.DrawLine(p, currentX, currentY, currentX, currentY - 12);
                                break;
                            default:
                                break;
                        }
                        num++;
                        currentX += Convert.ToInt32(perPixel);
                    }

                    currentX = startX;
                    currentY = startY;
                    num = 0;
                    while (num * perPixel <= axPanelPB.Height)
                    {
                        if (num * perPixel == axPanelPB.Height)
                        {
                            g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                            Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 30, 15);
                            Font aFont = new Font("Arial", 7, FontStyle.Regular);
                            g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                            aFont.Dispose();
                        }
                        else
                        {
                            switch (num % 4)
                            {
                                case 0:
                                    g.DrawLine(p, currentX, currentY, currentX - 20, currentY);

                                    Rectangle rect = new Rectangle(currentX - 20 + 1, currentY + 1, 30, 15);
                                    Font aFont = new Font("Arial", 7, FontStyle.Regular);
                                    g.DrawString((num * 2.54).ToString("0.0"), aFont, Brushes.Black, rect);
                                    aFont.Dispose();

                                    break;
                                case 1:
                                case 3:
                                    g.DrawLine(p, currentX, currentY, currentX - 8, currentY);
                                    break;
                                case 2:
                                    g.DrawLine(p, currentX, currentY, currentX - 12, currentY);
                                    break;
                                default:
                                    break;
                            }
                        }
                        num++;
                        currentY += Convert.ToInt32(perPixel);
                    }

                    p.Dispose();
                }



            }
            catch
            {
                MessageBox.Show("画线出错");
            }
        }
        Panel pRedLine = new Panel();

        public void DrawRedLine()//画出红线的位置
        {
            //Graphics g = this.PnlBigBoard.CreateGraphics();
            //g.Clear(PnlBigBoard.BackColor);
            //Pen p = new Pen(Color.Red, 1);

            if (DataTransfer.curTemplateInfo != null)
            {
                //int x = Convert.ToInt32(DataTransfer.curTemplateInfo.Length * DataTransfer.PERPIXEL);
                //int y = Convert.ToInt32(DataTransfer.curTemplateInfo.Height * DataTransfer.PERPIXEL);
                ////g.DrawLine(p, x, 0, x, y);

                //pRedLine.Height = y;
                //pRedLine.Location = new Point(x + 1, 0);
                //this.PnlBigBoard.Controls.Add(pRedLine);

                axPanelPB.ScaleHeight = DataTransfer.curTemplateInfo.Height * DataTransfer.CurPrinerInfo.PDPI;
                if (axPanelPB.Width != 0)
                {
                    axPanelPB.ScaleWidth = axPanelPB.ScaleHeight * axPanelPB.Width / axPanelPB.Height;
                }
                else
                {
                }
                axPanelPB.MaxWidth = Convert.ToInt32(DataTransfer.curTemplateInfo.Length * DataTransfer.CurPrinerInfo.PDPI);


            }

        }
        #endregion

        #region IPBMainView 成员
        public ChannelFactory<IOperateDB> _proxyOperateDB { get; set; }//创建代理
        public IOperateDB _OperateDb { get; set; }
        public void BindPhotoList(List<PhotoInfo_PBDCT> BindPhotoList)
        {
            GcPhotoInfo.DataSource = BindPhotoList;
            gvPhotoInfo.RefreshData();
        }
        public void BindPhotoList()
        {
            //GcPhotoInfo.DataSource = BindPhotoList;
            gvPhotoInfo.RefreshData();
        }
        public void BindOrderList(List<OrderInfo_PBDCT> resltOrdersList)
        {
            if (!timerDrawRedLine.Enabled)
            {
                timerDrawRedLine.Enabled = true;
            }
            if (xtraTabControl1.SelectedTabPageIndex == 0)
            {
                xtraTabControl1.SelectedTabPageIndex = 0;
            }
            GcOrderInfo.DataSource = resltOrdersList;
            gvOrderInfo.RefreshData();
            this.Text = "自动拼板,当前打印机：" + DataTransfer.CurPrinerInfo.PName + " ，当前连接IP：" + DataTransfer.IPadress;
            switch (DataTransfer.curTemplateInfo.BarCodeStatus)
            {
                case SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft: cmbBarCodeStatus.Text = "纵向";
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom: cmbBarCodeStatus.Text = "横向";
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode: cmbBarCodeStatus.Text = "无备注";
                    break;
                default:
                    break;
            }
            if (gvOrderInfo.RowCount > 0)
            {

                //if (_curSelectOrderProductId != 0)
                //{
                //    for (int i = 0; i < gvOrderInfo.RowCount; i++)
                //    {
                //        if (((OrderInfo_PBDCT)gvOrderInfo.GetRow(i)).order_Base_Info.OrderProductId == _curSelectOrderProductId)
                //        {
                //            gvOrderInfo.FocusedRowHandle = i;
                //            gvOrderInfo.SelectRow(i);

                //            break;
                //        }
                //    }
                //}
                // _selectedOrders.ForEach(delegate())
                if (_selectedOrders.Count > 0)
                {
                    for (int i = 0; i < gvOrderInfo.RowCount; i++)
                    {
                        int orderid = ((OrderInfo_PBDCT)gvOrderInfo.GetRow(i)).order_Base_Info.OrderProductId;

                        if (_selectedOrders.Where(p => p.order_Base_Info.OrderProductId == orderid).FirstOrDefault() != null)
                        {
                            gvOrderInfo.FocusedRowHandle = i;
                            gvOrderInfo.SelectRow(i);

                            break;
                        }
                    }
                }
                else
                {
                    gvOrderInfo.FocusedRowHandle = 0;
                }

                OrderInfo_PBDCT curOrder = (OrderInfo_PBDCT)gvOrderInfo.GetRow(gvOrderInfo.FocusedRowHandle);
                GcPhotoInfo.DataSource = curOrder.PhotoList;
                gvPhotoInfo.RefreshData();
            }
            else
            {
                GcPhotoInfo.DataSource = null;
                gvPhotoInfo.RefreshData();
            }
        }


        public string SelectTemplateName
        {
            get
            {
                if (cmbTemplate.SelectedItem == null)
                {
                    return null;
                }
                else
                {
                    return cmbTemplate.SelectedItem.ToString().Trim();
                }
            }
        }

        public string SelectOrderProductName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public string SelectPhotoSize
        {
            get
            {
                if (LBSize.SelectedItem == null)
                {
                    return string.Empty;
                } return LBSize.SelectedItem.ToString();
            }
        }

        public List<int> SelectPhotoIdList
        {
            get { throw new NotImplementedException(); }
        }



        /// <summary>
        /// 处理化相关控件的位置
        /// </summary>
        public void InitCtlsLoaction()
        {
            //axPanelPB.Left
            axPanelPB.Left = this.xtraTabControl1.Right + 25;
            axPanelPB.Top = this.toolStrip1.Height + 25;//new 25 表示用来画刻度的宽度 


            if (DataTransfer.curTemplateInfo == null || DataTransfer.curTemplateInfo.Height == 0 || DataTransfer.curTemplateInfo.Length == 0)
            {
                int wPix = Convert.ToInt32((float)this.axPanelPB.Width * 0.7 / 49);
                int hPix = Convert.ToInt32(this.axPanelPB.Height / 30);
                if (wPix >= hPix)
                {
                    DataTransfer.PERPIXEL = wPix;
                }
                else
                {
                    DataTransfer.PERPIXEL = hPix;
                }
                axPanelPB.Height = Convert.ToInt32(30 * DataTransfer.PERPIXEL);
            }
            else
            {
                int wPix = Convert.ToInt32((float)(this.Width - this.axPanelPB.Location.X) * 0.7 / DataTransfer.curTemplateInfo.Length);
                //int hPix = Convert.ToInt32((this.Height-this.axPanelPB.Location.Y) / DataTransfer.curTemplateInfo.Height);
                //if (wPix >= hPix)
                //{
                //    DataTransfer.PERPIXEL = wPix;
                //}
                //else
                //{
                //    DataTransfer.PERPIXEL = hPix;
                //}
                if (DataTransfer.curTemplateInfo.Height * wPix > this.Height * 0.4)
                {
                    wPix = Convert.ToInt32((this.Height * 0.4) / DataTransfer.curTemplateInfo.Height);

                }
                DataTransfer.PERPIXEL = wPix;
                axPanelPB.Height = Convert.ToInt32(DataTransfer.curTemplateInfo.Height * DataTransfer.PERPIXEL);
            }

            this.GcPhotoInfo.Top = axPanelPB.Bottom + 7;//new

            GcPhotoInfo.Height = this.Height - GcPhotoInfo.Top - statusStrip1.Height - 36;
            if (DataTransfer.curTemplateInfo == null)
            {
                cmbTemplate.Text = string.Empty;
            }
            else
            {
                cmbTemplate.Text = DataTransfer.curTemplateInfo.TemplateName;
            }
        }

        //public void BindCmbTempate(List<Tb_paperTemplate_Info> paperTemplateList)
        //{
        //    throw new NotImplementedException();
        //}

        public void BindPhotoSizeList(List<string> photoSizeList)
        {
            LBSize.Items.Clear();
            LBSize.DataSource = photoSizeList;
            LBSize.DisplayMember = "";
        }

        //public void BindClearGrid(List<PhotoInfo_PinBan> clearBoxPhotos)
        //{
        //    throw new NotImplementedException();
        //}

        public void ShowStatusMsg(string msg)
        {
            throw new NotImplementedException();
        }

        public void ShowPic(PicView picV)//将图片显示在大纸上
        {
            PnlBigBoard.Controls.Add(picV);
            picV.Focus();
            picV.Select();
        }
        public void ShowPic2(Array array)//将图片显示在大纸上
        {
            bool isDisplay = false;
            //_displayClear=

            axPanelPB.AddRectange(ref array, ref isDisplay);

        }
        public void ShowPicForAuto(Array array)//将图片显示在大纸上
        {
            bool isDisplay = false;
            _displayAuto = true;
            axPanelPB.ClearRectange();
            axPanelPB.AddRectange(ref array, ref isDisplay);

        }

        public void ClearBigBoard()
        {
            PnlBigBoard.Controls.Clear();
            this.gvPhotoInfo.RefreshData();
            ShowWaste("0%", Color.Red);
        }
        public void ClearBigBoard2()
        {
            axPanelPB.ClearRectange();
            this.gvPhotoInfo.RefreshData();
            ShowWaste("100%", Color.Red);
        }
        public void ShowWaste(string strWaste, Color c)
        {
            lblWate.Text = strWaste;
            lblWate.ForeColor = c;
        }

        public void RefushMainGrid()
        {
            gvPhotoInfo.RefreshData();
        }

        #endregion

        private void FrmMain_PinBan_Paint(object sender, PaintEventArgs e)
        {
            DrawScaleLine();
            DrawRedLine();
            axPanelPB.Width = this.Width - axPanelPB.Location.X;
            xtraTabControl1.Height = this.Height - statusStrip1.Height - xtraTabControl1.Location.Y - 36;
            GcPhotoInfo.Height = this.Height - statusStrip1.Height - GcPhotoInfo.Location.Y - 36;
            GcPhotoInfo.Width = this.Width - GcPhotoInfo.Location.X - 10;     
        }

        private void timerDrawRedLine_Tick(object sender, EventArgs e)
        {
            PnlBigBoard.Refresh();
            //DrawRedLine();
        }

        #region 从照片列表中托图动图片
        GridHitInfo downHitInfo = null;
        private void gvPhotoInfo_MouseDown(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            downHitInfo = null;

            GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));

            if (Control.ModifierKeys != Keys.None) return;
            if (e.Button == MouseButtons.Left && hitInfo.InRow && hitInfo.HitTest != GridHitTest.RowIndicator)
                downHitInfo = hitInfo;
        }

        private void gvPhotoInfo_MouseMove(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            if (e.Button == MouseButtons.Left && downHitInfo != null)
            {
                Size dragSize = SystemInformation.DragSize;
                Rectangle dragRect = new Rectangle(new Point(downHitInfo.HitPoint.X - dragSize.Width / 2,
                    downHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);
                string inputStr = "";
                if (!dragRect.Contains(new Point(e.X, e.Y)))//当他移出这个区域后就开始拖操作
                {
                    List<PhotoInfo_PBDCT> SelectedPhotos = GetDragData(view).OrderByDescending(or => or.Photo_Base_Info.Height).ToList();
                    RealLayoutPanel.RectangeView[] arrayRect = new RealLayoutPanel.RectangeView[SelectedPhotos.Count];
                    for (int i = 0; i < SelectedPhotos.Count; i++)
                    {
                        arrayRect[i].BarcodePixelWidth = DataTransfer.BarCodePixFactWidth;
                        arrayRect[i].BarcodePlace = (int)DataTransfer.curTemplateInfo.BarCodeStatus;
                        arrayRect[i].DPI = DataTransfer.CurPrinerInfo.PDPI;
                        arrayRect[i].filename = SelectedPhotos[i].Photo_Base_Info.PicPath;
                        if (comboBoxPhotoHV.SelectedIndex == 1)//横向放
                        {
                            if (SelectedPhotos[i].Photo_Base_Info.PixWidth >= SelectedPhotos[i].Photo_Base_Info.PixHeight)
                            {
                                arrayRect[i].isRotate = 0;
                            }
                            else
                            {
                                arrayRect[i].isRotate = 1;
                            }

                        }
                        else if (comboBoxPhotoHV.SelectedIndex == 2)//纵向放
                        {
                            if (SelectedPhotos[i].Photo_Base_Info.PixWidth >= SelectedPhotos[i].Photo_Base_Info.PixHeight)
                            {
                                arrayRect[i].isRotate = 1;
                            }
                            else
                            {
                                arrayRect[i].isRotate = 0;
                            }
                        }
                        else if (comboBoxPhotoHV.SelectedIndex == 0)
                        {
                            arrayRect[i].isRotate = 0;
                        }
                        else
                        {
                            arrayRect[i].isRotate = -1;

                        }
                        arrayRect[i].PictureHeight = Convert.ToInt32((decimal)SelectedPhotos[i].Photo_Base_Info.PixHeight / SelectedPhotos[i].Photo_Base_Info.DPI * DataTransfer.CurPrinerInfo.PDPI);
                        arrayRect[i].PictureID = SelectedPhotos[i].Photo_Base_Info.PhotoId;
                        arrayRect[i].PictureWidth = Convert.ToInt32((decimal)SelectedPhotos[i].Photo_Base_Info.PixWidth / SelectedPhotos[i].Photo_Base_Info.DPI * DataTransfer.CurPrinerInfo.PDPI);
                        //arrayRect[i].Unit = ComboBoxUnit.SelectedIndex;
                        inputStr += axPanelPB.RectangeToString(ref arrayRect[i]);
                    }

                    view.GridControl.DoDragDrop(inputStr, DragDropEffects.Copy);
                    downHitInfo = null;
                }
            }
        }

        private List<PhotoInfo_PBDCT> GetDragData(GridView view)
        {
            List<PhotoInfo_PBDCT> photoIdList = new List<PhotoInfo_PBDCT>();
            foreach (var piId in view.GetSelectedRows())
            {
                PhotoInfo_PBDCT pi = (PhotoInfo_PBDCT)view.GetRow(piId);
                if (pi.IsInBoard == false)
                {
                    photoIdList.Add(pi);
                }
            }
            return photoIdList;
        }
        private void gvPhotoInfo_MouseUp(object sender, MouseEventArgs e)
        {
            downHitInfo = null;
        }
        #endregion

        #region 接收拖到拼板PANEL上的图片
        private void PnlBigBoard_DragDrop(object sender, DragEventArgs e)
        {
            List<PhotoInfo_PBDCT> photoList = (List<PhotoInfo_PBDCT>)e.Data.GetData(typeof(List<PhotoInfo_PBDCT>));//接收到的照片实体
            //根据这些照片ID把他们放在应放的位置上
            Point currentPicLoacation = this.PnlBigBoard.PointToClient(new Point(e.X, e.Y));//currentPicLocation的从标为图片相对于大板的坐标
            //_presenter.DrawPic(photoList, currentPicLoacation);
            _presenter.NewDrawPic(photoList, currentPicLoacation);
        }

        private void PnlBigBoard_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(List<PhotoInfo_PBDCT>)))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }

        }
        #endregion

        private void gvPhotoInfo_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                PhotoInfo_PBDCT curPi = (PhotoInfo_PBDCT)this.gvPhotoInfo.GetRow(e.RowHandle);
                if (curPi == null)
                {
                    return;
                }
                if (curPi.IsInBoard)
                {
                    e.Appearance.BackColor = Color.GreenYellow;
                }
                else
                {
                    if (curPi.Priority >= 6)
                    {
                        e.Appearance.BackColor = Color.Pink;
                    }
                    if (curPi.Photo_Base_Info.IsClearBox)
                    {
                        e.Appearance.BackColor = Color.Red;
                    }
                }
            }
        }

        #region 多选图片、移动图片
        bool HaveAPanel = false;//是否有多选图片的临时PANEL
        bool MouseIsDown = false;//用于多选判断鼠标是否被按下
        Rectangle MouseRect = Rectangle.Empty;//将要画矩形框的大小
        List<PicView> selectedCtrls = new List<PicView>();//被 框选 的那些图片集合

        private void PnlBigBoard_MouseDown(object sender, MouseEventArgs e)
        {
            if (HaveAPanel)
            {

                //撤消多选
                _presenter.CancelMutilSelect();

                HaveAPanel = false;
            }

            MouseIsDown = true;
            DrawStart(e.Location);
        }

        private void PnlBigBoard_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseIsDown)
            {
                e.Location.Offset(PnlBigBoard.Location);
                ResizeToRectangle(e.Location);
            }
        }

        private void PnlBigBoard_MouseUp(object sender, MouseEventArgs e)
        {
            int minX, minY, maxX, maxY;
            int pixMinx, pixMinY, pixMaxX, pixMaxY;
            this.PnlBigBoard.Capture = false;
            Cursor.Clip = Rectangle.Empty;
            MouseIsDown = false;

            DrawRectangle();
            MouseRect = rectCorrection(MouseRect);


            foreach (Control ct in PnlBigBoard.Controls)
            {
                if ((ct is PicView) && MouseRect.IntersectsWith(((PicView)ct).Rect))
                {
                    selectedCtrls.Add((PicView)ct);
                }
            }
            if (selectedCtrls.Count <= 1)
            {
                selectedCtrls.Clear();
                return;
            }

            minX = selectedCtrls.Min(c => c.Location.X);
            minY = selectedCtrls.Min(c => c.Location.Y);

            maxX = selectedCtrls.Max(c => c.Location.X + c.Width);
            maxY = selectedCtrls.Max(c => c.Location.Y + c.Height);

            pixMinx = selectedCtrls.Min(C => C.PixFactX);
            pixMinY = selectedCtrls.Min(C => C.PixFactY);

            pixMaxX = selectedCtrls.Max(c => c.PixFactX + c.PixFacWidth);
            pixMaxY = selectedCtrls.Max(c => c.PixFactY + c.PixFacHeight);
            PicView pv = new PicView(maxX - minX, maxY - minY, new Point(minX, minY));
            pv.PixFactX = pixMinx;
            pv.PixFactY = pixMinY;
            _presenter.MultiSelectedPic(pv, selectedCtrls);
            ShowPic(pv);

            HaveAPanel = true;

            MouseRect = Rectangle.Empty;
        }

        private void DrawStart(Point StartPoint)
        {
            this.PnlBigBoard.Capture = true;
            Cursor.Clip = this.PnlBigBoard.RectangleToScreen(new Rectangle(0, 0, this.PnlBigBoard.Width, PnlBigBoard.Height));
            MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
        }

        private void ResizeToRectangle(Point p)
        {
            DrawRectangle();
            MouseRect.Width = p.X - MouseRect.Left;
            MouseRect.Height = p.Y - MouseRect.Top;
            DrawRectangle();
        }

        private void DrawRectangle()
        {
            Rectangle rect = this.PnlBigBoard.RectangleToScreen(MouseRect);
            ControlPaint.DrawReversibleFrame(rect, Color.YellowGreen, FrameStyle.Dashed);
        }

        //修正MouseRect 的值
        Rectangle rectCorrection(Rectangle oldRect)
        {
            if (oldRect.Width < 0)
            {
                oldRect.X += oldRect.Width;
                oldRect.Width *= -1;
            }
            if (oldRect.Height < 0)
            {
                oldRect.Y += oldRect.Height;
                oldRect.Height *= -1;
            }
            return new Rectangle(oldRect.X, oldRect.Y, oldRect.Width, oldRect.Height);
        }

        #endregion

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //_presenter.ClearBigBoard();
            axPanelPB.ClearRectange();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            toolStripButtonauto.Enabled = false;
            double waste = Convert.ToDouble(toolStripTextBoxWaste.Text.Trim());
            if (waste < 0 || waste > 100)
            {
                MessageBox.Show("请设置正确的浪费率");
                toolStripTextBoxWaste.Focus();
                return;
            }
            axPanelPB.ClearRectange();//上次清掉
            try
            {

                _presenter.AutoNPB(waste);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.Source + ex.StackTrace + ex.HelpLink + ex.InnerException + ex.GetBaseException().StackTrace);
                //throw ex;
            }
            finally
            {
                toolStripButtonauto.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }

        private void SetCurSelectOrderInfo()
        {
            OrderInfo_PBDCT curOrder = (OrderInfo_PBDCT)gvOrderInfo.GetRow(gvOrderInfo.FocusedRowHandle);
            if (curOrder != null)
            {
                _curSelectOrderProductId = curOrder.order_Base_Info.OrderProductId;
                _curSelectOrderRowid = gvOrderInfo.FocusedRowHandle;
                _curSelectSizeIndex = -1;
            }
        }


        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            toolStripButton3.Enabled = false;
            toolStripButtonauto.Enabled = false;
            RealLayoutPanel.RectangeView[] arrRV = (RealLayoutPanel.RectangeView[])axPanelPB.GetRectangeInfo();

            //List<PhotoInfo_PBDCT> listPhoto = (List<PhotoInfo_PBDCT>)GcPhotoInfo.DataSource;
            int boardType = comboBoxBoardType.SelectedIndex;

            if (arrRV.Length == 1 && arrRV[0].PictureID == 0)
            {
            }
            else
            {

                _presenter.PintCurBoard(arrRV, _currWaste, boardType);
            }
            toolStripButton3.Enabled = true;
            toolStripButtonauto.Enabled = true;


            this.Cursor = Cursors.Default;
        }

        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //复制产品份数
            int AddNum = 0;
            FrmNumSel frmNum = new FrmNumSel();
            if (frmNum.ShowDialog() == DialogResult.OK)
            {
                AddNum = frmNum.Num;
            }
            if (AddNum > 0)
            {
                //向数据库添加产品
                if (MessageBox.Show("确定要将选中的产品各复制" + AddNum + "份？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    SetCurSelectOrderInfo();
                    List<OrderInfo_PBDCT> SelectOrderList = new List<OrderInfo_PBDCT>();
                    foreach (var handleId in gvOrderInfo.GetSelectedRows())
                    {
                        SelectOrderList.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(handleId));
                    }

                    if (SelectOrderList.Count > 0)
                    {
                        _presenter.CopyOrder(SelectOrderList, AddNum);
                    }
                    else
                    {
                        MessageBox.Show("没有需要复制的产品");
                    }
                }
            }

        }

        private void 复制ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //复制照片
            int AddNum = 0;
            FrmNumSel frmNum = new FrmNumSel();
            if (frmNum.ShowDialog() == DialogResult.OK)
            {
                AddNum = frmNum.Num;
            }
            if (AddNum > 0)
            {

                //向数据库添加照片
                if (MessageBox.Show("确定要将选中的照片各复制" + AddNum + "份？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    SetCurSelectOrderInfo();
                    List<PhotoInfo_PBDCT> SelectPhotoList = new List<PhotoInfo_PBDCT>();
                    foreach (var handleId in this.gvPhotoInfo.GetSelectedRows())
                    {
                        SelectPhotoList.Add((PhotoInfo_PBDCT)gvPhotoInfo.GetRow(handleId));
                    }

                    if (SelectPhotoList.Count > 0)
                    {
                        _presenter.CopyPhoto(SelectPhotoList, AddNum);
                    }
                    else
                    {
                        MessageBox.Show("没有需要复制的照片");
                    }
                }
            }


        }

        private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //删除选中照片
            if (this.gvPhotoInfo.GetSelectedRows().Count() > 0)
            {
                if (MessageBox.Show("确定要将选中的照片删除", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    SetCurSelectOrderInfo();
                    List<PhotoInfo_PBDCT> SelectPhotoList = new List<PhotoInfo_PBDCT>();
                    foreach (var handleId in this.gvPhotoInfo.GetSelectedRows())
                    {
                        SelectPhotoList.Add((PhotoInfo_PBDCT)gvPhotoInfo.GetRow(handleId));
                    }

                    if (SelectPhotoList.Count > 0)
                    {
                        _presenter.DeletePhoto(SelectPhotoList);
                    }
                    else
                    {
                        MessageBox.Show("没有选中任何照片");
                    }
                }
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //删除选中的产品
            //删除选中照片
            if (this.gvOrderInfo.GetSelectedRows().Count() > 0)
            {
                if (MessageBox.Show("确定要将选中的照片删除", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    List<OrderInfo_PBDCT> SelectOrderList = new List<OrderInfo_PBDCT>();
                    foreach (var handleId in this.gvOrderInfo.GetSelectedRows())
                    {
                        SelectOrderList.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(handleId));
                    }

                    if (SelectOrderList.Count > 0)
                    {
                        _presenter.DeleteOrder(SelectOrderList);
                    }
                    else
                    {
                        MessageBox.Show("没有选中任何照片");
                    }
                }
            }
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //修改定单
            OrderInfo_PBDCT selectOI = (OrderInfo_PBDCT)gvOrderInfo.GetRow(gvOrderInfo.GetSelectedRows()[0]);
            if (selectOI != null)
            {
                SetCurSelectOrderInfo();
                ModifyOrder frmModify = new ModifyOrder(_OperateDb.GetAllPaperFace(), _OperateDb.GetAllPaperType(), _OperateDb);
                frmModify.ModifyOrderInfo = selectOI;
                frmModify.ShowDialog();

                _presenter.RushBind();
            }
        }

        private void gvOrderInfo_RowStyle(object sender, RowStyleEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                OrderInfo_PBDCT curOi = (OrderInfo_PBDCT)gvOrderInfo.GetRow(e.RowHandle);
                if (curOi != null)
                {

                    if (curOi.IsClearBox || curOi.Priority >= 6)
                        e.Appearance.BackColor = Color.Red;
                    if (curOi.IsAllPhotoInBoard == 2)//全部在
                    {
                        e.Appearance.BackColor = Color.GreenYellow;
                    }
                    else if (curOi.IsAllPhotoInBoard == 1)//部分在
                    {
                        e.Appearance.BackColor = Color.Yellow;
                    }


                }
            }
        }
        //List<int> SelectRows = new List<int>();
        private void gvOrderInfo_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            //将所有被选择的产品所对应的照片都显示在照片列表中

            _selectedOrders.Clear();
            if (gvOrderInfo.IsGroupRow(gvOrderInfo.FocusedRowHandle))
            {

                int rowHandles = gvOrderInfo.GetChildRowCount(gvOrderInfo.FocusedRowHandle);
                int endIndex = gvOrderInfo.GetChildRowHandle(gvOrderInfo.FocusedRowHandle, rowHandles - 1);
                int startIndex = gvOrderInfo.GetChildRowHandle(gvOrderInfo.FocusedRowHandle, 0);

                for (int i = startIndex; i <= endIndex; i++)
                {
                    if (i > -1)
                    {
                        _selectedOrders.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(i));
                    }
                }
                gvOrderInfo.ExpandGroupRow(gvOrderInfo.FocusedRowHandle, false);
            }
            else
            {
                foreach (var handler in gvOrderInfo.GetSelectedRows())
                {
                    if (handler > -1)
                    {
                        _selectedOrders.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(handler));
                    }
                }

                //_selectedOrders.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(gvOrderInfo.FocusedRowHandle));
            }
            _presenter.SelectOrder();

        }


        #region IPBMainView 成员

        List<OrderInfo_PBDCT> _selectedOrders = new List<OrderInfo_PBDCT>();
        public List<OrderInfo_PBDCT> GetSelectedOrder
        {
            get
            {
                //foreach (var handler in gvOrderInfo.GetSelectedRows())
                //{
                //    _selectedOrders.Add((OrderInfo_PBDCT)gvOrderInfo.GetRow(handler));
                //}

                return _selectedOrders;
            }
        }

        #endregion

        private void txtQuickSearch_TextChanged(object sender, EventArgs e)
        {
            //根据关键字快速过滤产品
            _presenter.filtrateOrderName();
        }

        #region IPBMainView 成员


        public string GetFiltrateString
        {
            get { return txtQuickSearch.Text.Trim(); }
        }
        public void ShowParas(PrinterDCT printer)
        {
            toolStripStatusLabel1.Text = "运行参数：机器" + printer.PName + "DPI：" + printer.PDPI + " 是否居中：" + (printer.IsMiddle ? "居中" : "不居中");
        }
        #endregion

        private void gvOrderInfo_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            try
            {
                if (e.RowHandle >= 0 && e.Column.Name == "gcOpenFile")
                {
                    //GridView view = sender as GridView;
                    //OrderInfo_PBDCT oiInfo = view.GetRow(e.RowHandle) as OrderInfo_PBDCT;
                    //string infoPath = oiInfo.order_Base_Info.OrderPath;
                    //CommonUtil.ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                    //                         new StringBuilder(infoPath), new StringBuilder(string.Empty), 1);
                }
                //_presenter.SelectOrder();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void gvPhotoInfo_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.RowHandle < 0)
            {

            }
            else
            {
                if (e.Column.Name == "gcPicPath")
                {
                    int ret = CommonUtil.WinExec(@"explorer /n,/select," + e.CellValue.ToString(), 1);

                }
                _curSelectPhotoRowId = e.RowHandle;
            }

        }

        private void GcPhotoInfo_DataSourceChanged(object sender, EventArgs e)
        {
            int totalNum = 0;
            if (_presenter != null)
            {
                totalNum = _presenter.GetTotalPhotoCount();
            }
            lblOrderPhotoMsg.Text = "产品：" + gvOrderInfo.RowCount + "   总照片数：" + totalNum + "    照片：" + gvPhotoInfo.RowCount;
        }
        public void ShowWaste(decimal waste)
        {
            toolStripTextBoxWaste.Text = waste.ToString();
        }
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //    if (this.toolStripButton4.Text.Equals("开启全自动"))
            //    {

            //        toolStripButtonauto.Enabled = false;
            //        double waste = Convert.ToDouble(toolStripTextBoxWaste.Text.Trim()) / 100;
            //        if (waste < 0 || waste > 1)
            //        {
            //            MessageBox.Show("请设置正确的浪费率");
            //            toolStripTextBoxWaste.Focus();
            //            return;
            //        }
            //        //全自动拼板

            //        _presenter.FullAutoPB(waste);
            //        this.Text = "自动拼版已经开启";
            //        this.toolStripButton4.Text = "关闭全自动";
            //    }
            //    else
            //    {
            //        this.toolStripButton4.Text = "开启全自动";
            //        toolStripButtonauto.Enabled = true;
            //        this.Text = "自动拼版";
            //        _presenter.ShutFullAutoPB();
            //    }
            _presenter.FullAutoPB();
        }

        private void LBSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (LBSize.Focused)
            {
                _presenter.FilterPhotoSize();
                _curSelectOrderProductId = 0;
                _curSelectOrderRowid = -1;
                _curSelectSizeIndex = LBSize.SelectedIndex;
            }
        }

        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (radioGroup1.SelectedIndex == 0)//全部
            //{
            //    _presenter.RushBind();
            //}
            //else if (radioGroup1.SelectedIndex == 1)//返工
            //{
            //    _presenter.BindRebackOrderList();
            //}
            //else//清柜
            //{
            //    _presenter.BindClearBoxOrderList();
            //}
        }

        private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (e.Page.Name == "tbPageSize")
            {
                _presenter.FilterPhotoSize();
            }
            else if (e.Page.Name == "GcOrderInfo")
            {
                _presenter.SelectOrder();
            }
            else
            { }
        }

        #region IPBMainView 成员


        public void RushOrderGrid()
        {
            gvOrderInfo.RefreshData();
        }

        #endregion

        private void gvOrderInfo_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void gvPhotoInfo_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        #region IPBMainView 成员


        public void BindTemplateCmd(List<BoardTemplate_DCT> paperTemplateList)
        {
            cmbTemplate.Items.Clear();
            foreach (var pt in paperTemplateList)
            {
                cmbTemplate.Items.Add(pt.TemplateName);
            }
            if (cmbTemplate.Items.Count > 0)
            {
                cmbTemplate.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("没有模板，请先设置模板");
            }

        }

        #endregion

        private void cmbTemplate_DropDownClosed(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                _presenter.GetSuitPhotosByTemplate(textBoxFileRemark.Text.Trim());
                axPanelPB.ClearRectange();
                comboBox1.SelectedIndex = 0;
            }
            catch
            { }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            _presenter.SwitchPrinter();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            _presenter.TemplateManage();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmMain_PinBan_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("确定退出拼板？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                axPanelPB.Dispose();
            }
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            if (toolStripButton8.Text == "显示图片")
            {
                toolStripButton8.Text = "不显示图片";
                DataTransfer.IsShowImg = true; ;
                axPanelPB.ShowPicture = true;
            }
            else
            {
                toolStripButton8.Text = "显示图片";
                DataTransfer.IsShowImg = false;
                axPanelPB.ShowPicture = false;
            }
            _presenter.ShowImgChanged();
            this.Cursor = Cursors.Default;
        }

        private void FrmMain_PinBan_Load_1(object sender, EventArgs e)
        {
            if (!_presenter.IniliData())
                this.Close();
            try
            {
                comboBoxBoardType.SelectedIndex = 1;
                IniFile.FilePath = Application.StartupPath;
                comboBoxPhotoHV.SelectedIndex = 0;
                pRedLine.BackColor = Color.Red;
                pRedLine.Width = 1;
                comboBox1.SelectedIndex = 0;
                ComboBoxUnit.SelectedIndex = 0;
                toolStripComboBoxType.SelectedIndex = 0;
                string SelectPhotoHVstr = IniFile.IniReadValue("PB", "SelectPhotoHV");
                if (string.IsNullOrEmpty(SelectPhotoHVstr))
                {
                    IniFile.IniWriteValue("PB", "SelectPhotoHV", "0");
                }
                comboBoxPhotoHV.SelectedIndex = Convert.ToInt32(IniFile.IniReadValue("PB", "SelectPhotoHV"));

                //toolStripComboBoxSmallType.SelectedIndex = 2;//5寸以下
                textBoxFileRemark.Text = IniFile.IniReadValue("PB", "BoardNameRemark");
                string WasteVstr = IniFile.IniReadValue("PB", "Waste");
                if (string.IsNullOrEmpty(WasteVstr))
                {
                    IniFile.IniWriteValue("PB", "Waste", "3");
                }
                toolStripTextBoxWaste.Text = IniFile.IniReadValue("PB", "Waste");
                axPanelPB.Width = this.Width - axPanelPB.Location.X;
                xtraTabControl1.Height = this.Height - statusStrip1.Height - xtraTabControl1.Location.Y - 36;
                GcPhotoInfo.Height = this.Height - statusStrip1.Height - GcPhotoInfo.Location.Y - 56;
                //DataTransfer.
                SmallERP.PinBan.PBDataTransfer.MinLengthPrs = IniFile.IniReadValue("PB", "MinLengthPrs");

                if (SmallERP.PinBan.PBDataTransfer.MinLengthPrs == null)
                {
                    IniFile.IniWriteValue("PB", "MinLengthPrs", "30");

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #region IPBMainView 成员


        public void RefushPanel()
        {
            //PnlBigBoard.Refresh();
        }

        #endregion

        private void comboBox1_DropDownClosed(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)//全部
            {
                //_presenter.RushBind(false);
            }
            else if (comboBox1.SelectedIndex == 1)//返工
            {
                _presenter.BindRebackOrderList();
            }
            else//清柜
            {
                _presenter.BindClearBoxOrderList();
            }
            gvOrderInfo.Focus();
        }
        public void RefushAutoNum(int Num)
        {
            this.Text = "自动拼板已开启,已累计自动拼版" + Num;
        }
        private void cmbBarCodeStatus_DropDownClosed(object sender, EventArgs e)
        {
            switch (cmbBarCodeStatus.Text)
            {
                case "纵向": DataTransfer.curTemplateInfo.BarCodeStatus = SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft;
                    break;
                case "横向": DataTransfer.curTemplateInfo.BarCodeStatus = SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom;
                    break;
                case "无备注": DataTransfer.curTemplateInfo.BarCodeStatus = SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode;
                    break;
                default: DataTransfer.curTemplateInfo.BarCodeStatus = SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode;
                    break;
            }
        }

        private void toolStripButtonImportPhoto_Click(object sender, EventArgs e)
        {
            //FrmImportPhoto frmImportPhoto = FrmImportPhoto.GetInstance;
            //frmImportPhoto.Rush += new FrmImportPhoto.RushControl(frmImportPhoto_Rush);
            //frmImportPhoto.Show();
            _presenter.ShowImport();

        }



        private void 打开目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //打开定单目录
            int rowHandle = gvOrderInfo.GetSelectedRows()[0];
            OrderInfo_PBDCT oiInfo = gvOrderInfo.GetRow(rowHandle) as OrderInfo_PBDCT;
            string infoPath = oiInfo.order_Base_Info.OrderPath;
            CommonUtil.ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                                     new StringBuilder(infoPath), new StringBuilder(string.Empty), 1);
        }

        private void 修改ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //删除选中照片
            if (this.gvPhotoInfo.GetSelectedRows().Count() > 0)
            {
                if (MessageBox.Show("修改照片尺寸", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    SetCurSelectOrderInfo();
                    List<PhotoInfo_PBDCT> SelectPhotoList = new List<PhotoInfo_PBDCT>();
                    foreach (var handleId in this.gvPhotoInfo.GetSelectedRows())
                    {
                        SelectPhotoList.Add((PhotoInfo_PBDCT)gvPhotoInfo.GetRow(handleId));
                    }

                    if (SelectPhotoList.Count > 0)
                    {
                        _presenter.UpdatePhoto(SelectPhotoList);
                        _presenter.RushBind(true);
                    }
                    else
                    {
                        MessageBox.Show("没有选中任何照片");
                    }
                }
            }
        }

        private void toolStripTextBox1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripTextBoxWaste_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void toolStripTextBoxWaste_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || e.KeyChar == (int)Keys.Back)
            {

            }
            else
            {
                e.Handled = true;
            }
        }

        private void toolStripButton9_Click(object sender, EventArgs e)
        {

        }
        int selectPhotoRowid = -1;
        private void gvPhotoInfo_DoubleClick(object sender, EventArgs e)
        {

            //双击一照片就自动将图片放到大板上
            PhotoInfo_PBDCT selectedPi = gvPhotoInfo.GetFocusedRow() as PhotoInfo_PBDCT;
            if (selectedPi != null)
            {
                if (selectedPi.IsInBoard)
                {
                    return;
                }
                List<PhotoInfo_PBDCT> templist = new List<PhotoInfo_PBDCT>();
                templist.Add(selectedPi);

                //_presenter.NewDrawPic(templist, new Point(0, 0));
                RealLayoutPanel.RectangeView[] arrayRect = new RealLayoutPanel.RectangeView[templist.Count];
                for (int i = 0; i < templist.Count; i++)
                {
                    arrayRect[i].BarcodePixelWidth = DataTransfer.BarCodePixFactWidth;
                    arrayRect[i].BarcodePlace = (int)DataTransfer.curTemplateInfo.BarCodeStatus;
                    arrayRect[i].DPI = DataTransfer.CurPrinerInfo.PDPI;
                    arrayRect[i].filename = templist[i].Photo_Base_Info.PicPath;
                    if (comboBoxPhotoHV.SelectedIndex == 1)//横向放
                    {
                        if (templist[i].Photo_Base_Info.PixWidth >= templist[i].Photo_Base_Info.PixHeight)
                        {
                            arrayRect[i].isRotate = 0;
                        }
                        else
                        {
                            arrayRect[i].isRotate = 1;
                        }

                    }
                    else if (comboBoxPhotoHV.SelectedIndex == 2)//纵向放
                    {
                        if (templist[i].Photo_Base_Info.PixWidth >= templist[i].Photo_Base_Info.PixHeight)
                        {
                            arrayRect[i].isRotate = 1;
                        }
                        else
                        {
                            arrayRect[i].isRotate = 0;
                        }
                    }
                    else
                    {
                        arrayRect[i].isRotate = 0;
                    }

                    arrayRect[i].PictureHeight = Convert.ToInt32((decimal)templist[i].Photo_Base_Info.PixHeight / templist[i].Photo_Base_Info.DPI * DataTransfer.CurPrinerInfo.PDPI);
                    arrayRect[i].PictureID = templist[i].PhotoId;
                    arrayRect[i].PictureWidth = Convert.ToInt32((decimal)templist[i].Photo_Base_Info.PixWidth / templist[i].Photo_Base_Info.DPI * DataTransfer.CurPrinerInfo.PDPI);
                    //arrayRect[i].Unit = ComboBoxUnit.SelectedIndex;
                }
                Array array = (Array)arrayRect;
                axPanelPB.AddRectange(ref array);
                axPanelPB.Focus();
            }


        }

        private void toolStripComboBoxUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            IniFile.FilePath = Application.StartupPath;

            if (ComboBoxUnit.SelectedIndex == 0)
            {
                IniFile.IniWriteValue("PB", "SelectUnit", "0");
                PBDataTransfer.SelectUnit = 0;
                axPanelPB.Unit = 0;
            }
            else
            {
                IniFile.IniWriteValue("PB", "SelectUnit", "1");
                PBDataTransfer.SelectUnit = 1;
                axPanelPB.Unit = 1;
            }

        }

        private void toolStripComboBoxType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (toolStripComboBoxType.SelectedIndex == 0)
            {
                DataTransfer.PERPIXEL = 10;

            }
            else
            {
                DataTransfer.PERPIXEL = 4;
            }

            DrawScaleLine();
            //cmbTemplate_DropDownClosed(sender, e);
        }

        private void toolStripComboBoxSmallType_DropDownClosed(object sender, EventArgs e)
        {

        }

        private void GcPhotoInfo_Click(object sender, EventArgs e)
        {

        }

        private void textBoxFileRemark_TextChanged(object sender, EventArgs e)
        {
            DataTransfer.curTemplateInfo.BoardNameRemark = textBoxFileRemark.Text.Trim();
            IniFile.IniWriteValue("PB", "BoardNameRemark", textBoxFileRemark.Text.Trim());
            PBDataTransfer.BoardNameRemark = textBoxFileRemark.Text.Trim();

        }

        private void toolStripButtonWatch_Click(object sender, EventArgs e)
        {
            FrmSeachPhoto frm = new FrmSeachPhoto();
            frm._OperateDb = _OperateDb;
            frm.ShowDialog();
        }

        private void axPanelPB_RectangeAdd(object sender, AxRealLayoutPanel.__Panel_RectangeAddEvent e)
        {
            int[] picidArray = (int[])e.pictureID;
            //if (picidArray.Length > 0)
            //{
            //    List<PhotoInfo_PBDCT> listView = (List<PhotoInfo_PBDCT>)GcPhotoInfo.DataSource;
            //    for (int i = 0; i < picidArray.Length; i++)
            //    {
            //        listView.FirstOrDefault(p => p.PhotoId == picidArray[i]).IsInBoard = true;
            //    }

            //}
            if (!_displayAuto)
            {

                _presenter.ChangePhotoStatus(picidArray, true);
            }
            else
            {
                _displayAuto = false;
            }
            // toolStripLabel10.Text = (axPanelPB.GetWastePercent()*100).ToString("0.00");
        }

        private void axPanelPB_RectangeDelete(object sender, AxRealLayoutPanel.__Panel_RectangeDeleteEvent e)
        {
            int[] picidArray = (int[])e.pictureID;
            //if (picidArray.Length > 0)
            //{
            //    List<PhotoInfo_PBDCT> listView = (List<PhotoInfo_PBDCT>)GcPhotoInfo.DataSource;
            //    for (int i = 0; i < picidArray.Length; i++)
            //    {
            //        listView.FirstOrDefault(p => p.PhotoId == picidArray[i]).IsInBoard = false;
            //    }

            //}
            //GcPhotoInfo.RefreshDataSource();
            if (!_displayAuto)
            {
                _presenter.ChangePhotoStatus(picidArray, false);
            }
            else
            {
                _displayAuto = false;
            }
        }

        private void axPanelPB_RectangeClear(object sender, AxRealLayoutPanel.__Panel_RectangeClearEvent e)
        {
            int[] picidArray = (int[])e.pictureID;
            //if (picidArray.Length > 0)
            //{
            //    List<PhotoInfo_PBDCT> listView = (List<PhotoInfo_PBDCT>)GcPhotoInfo.DataSource;
            //    for (int i = 0; i < picidArray.Length; i++)
            //    {
            //        listView.FirstOrDefault(p => p.PhotoId == picidArray[i]).IsInBoard = false;
            //    }

            //}
            //GcPhotoInfo.RefreshDataSource();
            if (!_displayAuto)
            {
                _presenter.ChangePhotoStatus(picidArray, false);
            }
            else
            {
                _displayAuto = false;
            }
        }

        private void 横向ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void ComboBoxUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ComboBoxUnit.SelectedIndex == 0)
            {
                IniFile.IniWriteValue("PB", "SelectUnit", "0");
                PBDataTransfer.SelectUnit = 0;
                axPanelPB.Unit = 0;
            }
            else
            {
                IniFile.IniWriteValue("PB", "SelectUnit", "1");
                PBDataTransfer.SelectUnit = 1;
                axPanelPB.Unit = 1;
            }

        }
        decimal _currWaste = 0;
        private void axPanelPB_WastePercentChange(object sender, AxRealLayoutPanel.__Panel_WastePercentChangeEvent e)
        {
            _currWaste = (decimal)e.wastePercent;
            this.toolStripLabelWaste.Text = (_currWaste * 100).ToString("0.00") + "%";
        }
        public void SetSelected()
        {
            if (xtraTabControl1.SelectedTabPageIndex == 0)
            {
                ;
                if (_curSelectOrderRowid >= 0)
                {
                    gvOrderInfo.SelectRow(_curSelectOrderRowid);
                }
                else
                {
                    gvOrderInfo.SelectRow(0);
                }
                //_presenter.SelectOrder();
                List<PhotoInfo_PBDCT> list = new List<PhotoInfo_PBDCT>();
                OrderInfo_PBDCT order = ((OrderInfo_PBDCT)gvOrderInfo.GetFocusedRow());
                if (order != null)
                {
                    list = order.PhotoList;
                    BindPhotoList(list);
                }
            }
            else
            {

                if (_curSelectSizeIndex >= 0)
                {
                    LBSize.SelectedIndex = _curSelectSizeIndex;
                }
                else
                {
                    LBSize.SelectedIndex = 0;
                }
                //LBSize_SelectedIndexChanged(this, null);
                _presenter.FilterPhotoSize();
                if (_curSelectPhotoRowId != -1)
                {
                    gvPhotoInfo.ClearSelection();
                    gvPhotoInfo.SelectRow(_curSelectPhotoRowId);
                    //gvPhotoInfo.
                }
                //gvPhotoInfo.RefreshData();

            }
            //讲版上的照片设定成已经在版上
            List<OrderInfo_PBDCT> listOrder = (List<OrderInfo_PBDCT>)gvOrderInfo.DataSource;
            //axPanelPB.ge
            RealLayoutPanel.RectangeView[] arrRV = (RealLayoutPanel.RectangeView[])axPanelPB.GetRectangeInfo();
            if (arrRV.Length > 1)
            {
                for (int i = 0; i < arrRV.Length; i++)
                {
                    //listOrder.ForEach(o => o.PhotoList.FirstOrDefault(p => p.PhotoId == arrRV[i].PictureID).IsInBoard = true);
                    foreach (OrderInfo_PBDCT order in listOrder)
                    {
                        foreach (PhotoInfo_PBDCT ph in order.PhotoList)
                        {
                            if (ph.PhotoId == arrRV[i].PictureID)
                            {
                                ph.IsInBoard = true;
                            }
                        }
                    }
                }
            }



        }

        private void LBSize_Click(object sender, EventArgs e)
        {
            if (LBSize.SelectedIndex >= 0)
            {
                _curSelectOrderRowid = -1;
                _curSelectOrderProductId = 0;
                _curSelectSizeIndex = LBSize.SelectedIndex;
            }
        }

        private void gvPhotoInfo_CustomColumnSort(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnSortEventArgs e)
        {

        }

        private void gvOrderInfo_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                OrderInfo_PBDCT order = (OrderInfo_PBDCT)gvOrderInfo.GetRow(e.RowHandle);
                if (order != null)
                {
                    if (e.Column.Name == "gcOpenFile")
                    {
                        if (Convert.ToBoolean(string.IsNullOrEmpty(IniFile.IniReadValue("PB", "isForcePrint")) ? "False" : IniFile.IniReadValue("PB", "isForcePrint")))
                        {
                            if (order.Priority == 0)
                            {
                                e.DisplayText = "普通";
                            }
                            else
                            {
                                e.DisplayText = "加急";
                            }
                        }
                        else
                        {
                            e.DisplayText = "普通";
                        }

                    }
                }

            }
        }

        private void gvPhotoInfo_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                PhotoInfo_PBDCT photo = (PhotoInfo_PBDCT)gvPhotoInfo.GetRow(e.RowHandle);

                if (photo != null)
                {
                    if (e.Column.Name == "gcPriority")
                    {
                        if (PBDataTransfer.isForcePrint)
                        {
                            if (photo.Priority == 0)
                            {
                                e.DisplayText = "普通";
                            }
                            else
                            {
                                e.DisplayText = "加急";
                            }
                        }
                        else
                        {
                            e.DisplayText = "普通";
                        }
                    }
                    if (photo.Photo_Base_Info.IsContentDXF)
                    {
                        // e.Appearance.BackColor = Color.LightSkyBlue;
                    }
                }
                //    else if (e.Column.Name == "gc_DXFCol")
                //    {
                //        string rV = e.CellValue as string;
                //        if (!string.IsNullOrEmpty(rV))
                //        {
                //            e.Appearance.BackColor = Color.LimeGreen;
                //        }
                //    }
                //}

            }
        }

        private void comboBoxPhotoHV_SelectedIndexChanged(object sender, EventArgs e)
        {

            IniFile.IniWriteValue("PB", "SelectPhotoHV", comboBoxPhotoHV.SelectedIndex.ToString());
            PBDataTransfer.SelectPhotoHV = comboBoxPhotoHV.SelectedIndex;

        }

        private void 裁切ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<PhotoInfo_PBDCT> SelectPhotoList = new List<PhotoInfo_PBDCT>();
            foreach (var handleId in this.gvPhotoInfo.GetSelectedRows())
            {
                SelectPhotoList.Add((PhotoInfo_PBDCT)gvPhotoInfo.GetRow(handleId));
            }

            if (SelectPhotoList.Count > 0)
            {
                FrmCutPic frm = new FrmCutPic();
                frm._SrcPhotoList = SelectPhotoList;
                frm.SavePhotoToDB += new FrmCutPic.HandPhotoInfo(frm_SavePhotoToDB);
                frm.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择需要裁切的照片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ;
            }

        }

        private void toolStripButtonCutPic_Click(object sender, EventArgs e)
        {
            List<PhotoInfo_PBDCT> SelectPhotoList = new List<PhotoInfo_PBDCT>();
            foreach (var handleId in this.gvPhotoInfo.GetSelectedRows())
            {
                SelectPhotoList.Add((PhotoInfo_PBDCT)gvPhotoInfo.GetRow(handleId));
            }

            if (SelectPhotoList.Count > 0)
            {
                FrmCutPic frm = new FrmCutPic();
                frm._SrcPhotoList = SelectPhotoList;
                frm.SavePhotoToDB += new FrmCutPic.HandPhotoInfo(frm_SavePhotoToDB);
                frm.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择需要裁切的照片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ;
            }
        }

        int frm_SavePhotoToDB(List<PhotoInfo_PBDCT> list)
        {
            List<int> rtnListPhotoid = _presenter.UpdatePhotoSize(list);
            List<PhotoInfo_PBDCT> listSrc = (List<PhotoInfo_PBDCT>)GcPhotoInfo.DataSource;
            foreach (int photoid in rtnListPhotoid)
            {
                PhotoInfo_PBDCT photoSrc = listSrc.FirstOrDefault(p => p.Photo_Base_Info.PhotoId == photoid);
                PhotoInfo_PBDCT photoTo = list.FirstOrDefault(p => p.Photo_Base_Info.PhotoId == photoid);
                if (photoSrc != null && photoTo != null)
                {
                    if (File.Exists(photoSrc.PicPath))
                    {
                        File.Delete(photoSrc.PicPath);
                    }
                    photoSrc.Photo_Base_Info.Width = photoTo.Photo_Base_Info.Width;
                    photoSrc.Photo_Base_Info.Height = photoTo.Photo_Base_Info.Height;
                    photoSrc.Photo_Base_Info.PixHeight = photoTo.Photo_Base_Info.PixHeight;
                    photoSrc.Photo_Base_Info.PixWidth = photoTo.Photo_Base_Info.PixWidth;
                    photoSrc.Photo_Base_Info.DPI = photoTo.Photo_Base_Info.DPI;
                    photoSrc.Photo_Base_Info.PicPath = photoTo.Photo_Base_Info.PicPath;

                }
            }
            GcPhotoInfo.RefreshDataSource();
            return 0;
        }

        private void ToolStripMenuItemDXFFile_Click(object sender, EventArgs e)
        {
            //int rowHandle = gvOrderInfo.GetSelectedRows()[0];
            //OrderInfo_PBDCT oiInfo = gvOrderInfo.GetRow(rowHandle) as OrderInfo_PBDCT;
            //FrmAssignDxf frmAssignDxf = new FrmAssignDxf(oiInfo);
            //if (DialogResult.OK == frmAssignDxf.ShowDialog())
            //{
            //   bool r= _presenter.UpdateOrderDex(oiInfo);
            //}


        }

        private void ToolStripMenuItemChangeDXF_Click(object sender, EventArgs e)
        {
            try
            {
                int rowHandle = gvPhotoInfo.GetSelectedRows()[0];
                PhotoInfo_PBDCT photoInfoPbdct = gvPhotoInfo.GetRow(rowHandle) as PhotoInfo_PBDCT;
                WriteLogForCheck.WriteLogFile(Environment.CurrentDirectory.ToString());
                FrmAssignDxf frmAssignDxf = new FrmAssignDxf(photoInfoPbdct);
                if (DialogResult.OK == frmAssignDxf.ShowDialog())
                {
                    bool r = _presenter.UpdatePhotoDxf(photoInfoPbdct);
                }
                gvPhotoInfo.RefreshData();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }

        private void comboBoxBarcodeWidth_DropDownClosed(object sender, EventArgs e)
        {
                 
        }

        private void but_PrintCode_Click(object sender, EventArgs e)
        {
            FrmControl.FrmPrint print = new FrmControl.FrmPrint(this);
            print.ShowDialog();
        }

    }
}
